import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:rainflutter/config/routes.dart';
import 'package:rainflutter/extends/no_splash.dart';

void main() => runApp(MyApp());

class LoginState {
  bool isLogin = false;

  @override
  bool operator ==(other) {
    return isLogin == (other as LoginState).isLogin;
  }

  @override
  int get hashCode => super.hashCode;
}

class InheritedLoginWidget extends InheritedWidget {
  final LoginState loginState;

  InheritedLoginWidget({this.loginState, Widget child}) : super(child: child);

  static InheritedLoginWidget of(BuildContext context) =>
      context.dependOnInheritedWidgetOfExactType<InheritedLoginWidget>();

  @override
  bool updateShouldNotify(InheritedLoginWidget oldWidget) {
    return oldWidget.loginState == this.loginState;
  }
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.

  @override
  Widget build(BuildContext context) {
    // debugProfileBuildsEnabled = true;
    // debugProfilePaintsEnabled = true;
    // debugPaintLayerBordersEnabled = true;

    return InheritedLoginWidget(
      loginState: LoginState(),
      child: MaterialApp(
        title: 'Flutter Rain Demo',
        theme: ThemeData(
            primarySwatch: Colors.blue,
            // splashFactory: NoSplashFactory(),
            outlinedButtonTheme: OutlinedButtonThemeData(
                style: ButtonStyle(
                    overlayColor:
                        MaterialStateProperty.all(Colors.transparent))),
            elevatedButtonTheme: ElevatedButtonThemeData(
                style: ButtonStyle(
                    overlayColor:
                        MaterialStateProperty.all(Colors.transparent))),
            textButtonTheme: TextButtonThemeData(
                style: ButtonStyle(
                    overlayColor:
                        MaterialStateProperty.all(Colors.transparent))),
            splashColor: Colors.green,
            // highlightColor: Colors.pink,
            hintColor: Colors.yellow),
        home: MyHomePage(title: 'demo'),
        navigatorKey: Routes.navigatorKey,
        onGenerateRoute: (RouteSettings setting) {
          var builder = routeTable[setting.name];

          return CupertinoPageRoute(
            builder: builder,
            settings: setting,
          );
        },
        onUnknownRoute: (RouteSettings setting) {
          var home = routeTable[Routes.MyHomePage];
          return CupertinoPageRoute(
            builder: home,
            settings: setting,
          );
        },
        navigatorObservers: [],
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: SingleChildScrollView(
            child: Wrap(
                spacing: 5,
                runSpacing: 5,
                children: List.generate(chickList.length, (index) {
                  return customButton(
                    chickList[index]['name'],
                    chickList[index]['routes'],
                    arguments: chickList[index]['arguments'],
                  );
                }).toList())));
  }

  Widget customButton(String labl, String link, {Object arguments}) {
    return Container(
      child: RaisedButton(
        onPressed: () {
          Navigator.of(context).pushNamed(link, arguments: arguments);
        },
        child: Text(
          labl,
          style: new TextStyle(height: 1),
        ),
      ),
    );
  }
}
